package com.zznode.redsun.commons.dto;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;

import com.zznode.csp.domain.commons.util.DomainBeanUtils;
import com.zznode.redsun.commons.utils.GlobalUtils;
import com.zznode.redsun.smartcrm.model.ConsumeRecord;
import com.zznode.redsun.smartcrm.model.Customer;
import com.zznode.redsun.smartcrm.model.Product;

public class ConsumeDto {
	private Long id;

	private Long customerId;
	private String customerCode;
	private String customerName;

	private Long productId;
	private String productCode;
	private String productName;

	private Long quantity;

	private BigDecimal amount;

	private Date createTime;
	private String createTimeString;

	private Long createUserId;
	private String createUserName;

	private String description;

	public static ConsumeDto create(ConsumeRecord entity) {
		ConsumeDto dto = new ConsumeDto();
		dto.setId(entity.getId());
		if (null != entity.getCustomer()) {
			dto.setCustomerId(entity.getCustomer().getId());
			dto.setCustomerCode(entity.getCustomer().getCode());
			dto.setCustomerName(entity.getCustomer().getName());
		}
		if (null != entity.getProduct()) {
			dto.setProductId(entity.getProduct().getId());
			dto.setProductCode(entity.getProduct().getCode());
			dto.setProductName(entity.getProduct().getName());
		}
		dto.setQuantity(entity.getQuantity());
		dto.setAmount(entity.getAmount());
		dto.setCreateTime(entity.getCreateTime());
		dto.setCreateTimeString(GlobalUtils.formartDateTime(entity.getCreateTime()));
		dto.setCreateUserId(entity.getCreateUser().getId());
		dto.setCreateUserName(entity.getCreateUser().getName());
		dto.setDescription(entity.getDescription());

		return dto;
	}

	public void update(ConsumeRecord entity) {
		entity.setAmount(amount);
		entity.setCreateTime(createTime == null ? Calendar.getInstance().getTime() : createTime);
		entity.setCustomer(DomainBeanUtils.create(Customer.class, customerId));
		entity.setDescription(description);
		entity.setProduct(DomainBeanUtils.create(Product.class, productId));
		entity.setQuantity(quantity);
	}

	public ConsumeRecord convert() {
		ConsumeRecord entity = new ConsumeRecord();
		update(entity);
		return entity;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getCustomerId() {
		return customerId;
	}

	public void setCustomerId(Long customerId) {
		this.customerId = customerId;
	}

	public String getCustomerName() {
		return customerName;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	public Long getProductId() {
		return productId;
	}

	public void setProductId(Long productId) {
		this.productId = productId;
	}

	public String getProductName() {
		return productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	public Long getQuantity() {
		return quantity;
	}

	public void setQuantity(Long quantity) {
		this.quantity = quantity;
	}

	public BigDecimal getAmount() {
		return amount;
	}

	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getCreateTimeString() {
		return createTimeString;
	}

	public void setCreateTimeString(String createTimeString) {
		this.createTimeString = createTimeString;
	}

	public Long getCreateUserId() {
		return createUserId;
	}

	public void setCreateUserId(Long createUserId) {
		this.createUserId = createUserId;
	}

	public String getCreateUserName() {
		return createUserName;
	}

	public void setCreateUserName(String createUserName) {
		this.createUserName = createUserName;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getCustomerCode() {
		return customerCode;
	}

	public void setCustomerCode(String customerCode) {
		this.customerCode = customerCode;
	}

	public String getProductCode() {
		return productCode;
	}

	public void setProductCode(String productCode) {
		this.productCode = productCode;
	}
}
